<template>
  <div>
    <h1>我是首页</h1>
    <button @click="addNumAsync(10)">异步+</button>
    <button @click="addNum(5)">+</button>
    {{ $store.state.num }}
    <button @click="reduceNum">-</button>
  </div>
</template>

<script>
export default {
  methods: {
    addNumAsync (n) {
      // 组件中如何触发 action
      this.$store.dispatch('add_num_async', n)
    },
    addNum (n) {
      this.$store.commit('add_num', n)
    },
    reduceNum () {}
  },
  mounted () {
    console.log(this.$store)
    // state是数据 commit 提交mutation
  }
}
</script>

<style lang="scss" scoped>

</style>
